package com.yc.bos.service.impl;

import com.yc.bos.dao.IWorkordermanageDao;
import com.yc.bos.model.Workordermanage;
import com.yc.bos.service.IWorkordermanageService;
import com.yc.bos.service.base.BaseServiceImpl;
import org.activiti.engine.RuntimeService;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class WorkordermanageServiceImpl extends BaseServiceImpl<Workordermanage> implements IWorkordermanageService {

    @Autowired
    private RuntimeService rs;
    @Autowired
    private IWorkordermanageDao workordermanageDao;
    @Override
    public void save(Workordermanage entity) {
        workordermanageDao.save(entity);
    }

    @Override
    public void update(Workordermanage entity) {

    }

    @Override
    public void delete(Workordermanage entity) {

    }

    @Override
    public Workordermanage findById(Serializable id) {
        return null;
    }

    @Override
    public List<Workordermanage> findAll() {
        return null;
    }

    @Override
    public List<Workordermanage> findAllWithNoStart() {
        DetachedCriteria dc=DetachedCriteria.forClass(Workordermanage.class);
        dc.add(Restrictions.eq("start","0"));
        return workordermanageDao.findAllByDetachedCriteria(dc);
    }

    @Override
    public void start(String id) {
        //启动配送流程
        //1.根据id查找Workordermanager
        Workordermanage wom=workordermanageDao.findById(id);
        wom.setStart("1");
        Map<String,Object>  info=new HashMap<String, Object>();
        info.put("orderInfo",wom.toString());
        String businessId=wom.getId();
        rs.startProcessInstanceByKey("transfer",businessId,info);
    }
}
